﻿$(function () {
    //********************************
    // Main Namespace
    //********************************

    if (typeof (Main) === "undefined") {
        Main = {};
    }

    //Gets the Pivot div element
    Main.GetPivotDiv = function (metroPivot, index) {
        //get items div
        var item = metroPivot.children()[1]; //index 0 is the header;
        //get pivotItem div
        var pivotItem = $(item).children()[index];
        //pivot-item div
        return $(pivotItem).children()[0];
    };

    //Initializes the Metro Pivot control
    Main.InitMetroPivot = function () {
        $("section.metro-pivot").metroPivot({
            selectedItemChanged: function (index) {
                var pivotItem = Main.GetPivotDiv(this, index);
                var url = $(pivotItem).attr("url");
                //call the controller action for the url attached
                $.ajax({
                    type: "GET",
                    url: url,
                    success: function (data, textStatus, jqXHR) {
                        $(pivotItem).html(data);
                    }
                });
            }
        });
    };


});